package com.example.design.iterator.test1;

import java.util.Iterator;

/**
 * 服务员，通过迭代器，服务员能用同一个接口返回不同类型的菜单
 */
public class Waitress {
    Menu cafeMenu;
    Menu doubleDragonMenu;

    public Waitress(Menu cafeMenu, Menu doubleDragonMenu){
        this.cafeMenu = cafeMenu;
        this.doubleDragonMenu = doubleDragonMenu;
    }

    public void printMenu(){
        Iterator doubleDragonIterator = doubleDragonMenu.createIterator();
        Iterator cafeIterator = cafeMenu.createIterator();
        System.out.println("打印双截龙菜单。。。。。。");
        printMenu(doubleDragonIterator);
        System.out.println();
        System.out.println("打印咖啡菜单。。。。。。");
        printMenu(cafeIterator);
    }

    private void printMenu(Iterator iterator){
        while (iterator.hasNext()){
            MenuItem item = (MenuItem)iterator.next();
            System.out.println("名称：" +item.getName()
                    +",单价：" + item.getPrice() + "，菜单说明：" + item.getDescription());
        }
    }
}
